<?php
ob_start();
session_start();
	include ("../BusinessLogicTier/DanhMucSPBUS.php");
	include ("../BusinessLogicTier/SanPhamBUS.php");
	require_once '../DataAccessTier/DBConnection.php'; 
	include ("../BusinessLogicTier/TinRaoVatBUS.php");
	require_once '../BusinessLogicTier/ThongTinNguoiDungBUS.php';
	require_once '../BusinessLogicTier/TinhBUS.php';
	include ("../BusinessLogicTier/VungBUS.php");
	include ("../BusinessLogicTier/BinhLuanBUS.php");
	include ("../BusinessLogicTier/NguoiDungBUS.php");
	include ("../BusinessLogicTier/LoaiTinRaoVatBUS.php");
header('Content-Type: text/html; charset=UTF-8');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/sanpham.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>rao vặt</title>
<!-- InstanceEndEditable -->
<link rel="stylesheet" type="text/css" href="css/timkiem.css"/>
<link rel="stylesheet" type="text/css" href="css/chitietraotin.css"/>
<link rel="stylesheet" type="text/css" href="css/top.css"/>
<link rel="stylesheet" type="text/css" href="css/header.css"/>
<link rel="stylesheet" type="text/css" href="css/menutab.css"/>
<link rel="stylesheet" type="text/css" href="css/navigation.css"/>
<link rel="stylesheet" type="text/css" href="css/leftcontent.css"/>
<link rel="stylesheet" type="text/css" href="css/centercontent.css"/>
<link rel="stylesheet" type="text/css" href="css/rightcontent.css"/>
<link rel="stylesheet" type="text/css" href="css/footer.css"/>
<link rel="stylesheet" type="text/css" href="css/sanpham.css"/>
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
</head>

<body>
 	<!-- InstanceBeginEditable name="EditRegion4" -->
 	
 	<!-- InstanceEndEditable -->
 	<div class="main">
 		<!--Top: Start-->   
    	<div class="top">
<?php include("top/top.php") ?>             
               
        </div>
        <!--Top: end-->
        <!-- header: start -->
        <div class="header">
<?php include("top/header.php") ?>
        </div>
        	
        <!--header:end-->
        <div class="clr"></div><!--*xóa đi phần float left, float right*/--> 
        <!--content:start-->
        
        <div class="content">
        	<!--menu tap -->
        	<div id="menu_tap">
<?php include("content/menu.php") ?>
          		 
            </div>
          	<!--navigation-->
            <div class="navigation"><span class="current"></span></div>
            <!--tim kiem -->
             <div class="timkiem_nv"> <?php include("content/timkiem.php") ?>
             </div>
             <!--left content-->
             <div class="left_content">
            
<?php include("content/left.php") ?>
            </div>
            <!--center content-->
            <div class="center_content"><!-- InstanceBeginEditable name="timkiemsanpham" -->
            <div class="center_title_bar">Chi Tiết Sản Phẩm</div>
            <?php 
			$stt=0;				 
			$cttrvBUS = new TinRaoVatBUS();		 
			$sanphamBUS= new SanPhamBUS();
			$ttnguoidungBUS = new ThongTinNguoiDungBUS();
			$tinhBUS = new TinhBUS();
			$binhluanBUS= new BinhLuanBUS();
			
			$nguoidungBUS= new NguoiDungBUS();
			$loaitrvBUS = new  LoaiTinRaoVatBUS();
			
			$idMaTrv= $_GET["idMatrv"];
			$soluongbl = $binhluanBUS->getSoLuongBinhLuanByMaTRV($idMaTrv);
			$sodong = 51;//số bình luận trên 1 trang
			$sotrang = ceil($soluongbl/$sodong);
			if(!isset($_GET["p"]))
				$p=1;//p là trang
			else
				$p = $_GET["p"];
			$x = ($p-1)*$sodong;
			
			
			$idMaND = "2";
			//lấy thông tin rao vặt thông qua mã rao vặt
			$cttrv = $cttrvBUS->getTinRaoVatByMaTRV($idMaTrv);
			//lấy thông tin người dùng rao tin thông qua mã người dũng trong chi tiết rao vặt
			$ttnguoidung = $ttnguoidungBUS->getThongTinNguoiDungByMaND($cttrv->getMaND());
			//lấy thông tin tỉnh rao vặt thông qua mã tin rao vặt
			$tinh = $tinhBUS->getTinhByMaTRV($idMaTrv);
			//lấy thông tin bình luận thông qua mã tin rao vặt
			$binhluan= $binhluanBUS->getBinhLuanByMaTRV($idMaTrv, $x, $sodong);

			//lấy thông tin người dùng đăng nhập thông qua mã người dùng
			$ttnguoidungdn = $ttnguoidungBUS->getThongTinNguoiDungByMaND($idMaND);			
			
			?>
                     <div id="tinraovat">
                        <div class="title_tinrao"><?php echo $cttrv->getTieuDe();?>
                        </div>
                        <div class="thongtin_tinrao"><font size="+2">Thông Tin Rao Vặt </font><br />
                            Người Đăng: <?php if(ttnguoidung!=NULL) echo  $ttnguoidung->getTenHienThi();?> </br>        
                            Nơi Bán: <?php if($tinh!=NULL)foreach($tinh as $objtinhmrv) echo " ".$objtinhmrv->getTenTinh();?> <br />
                            Giá Sản Phẩm: <?php echo $cttrv->getGiaCa(); ?> vnd <br />
                            Loại Tin: <?php echo $loaitrvBUS->getLoaiTRVByMaLoaiTRV($cttrv->getMaLoaiTRV())->getTenLoaiTRV();?> Sản Phẩm<br />
                            Ngày Đăng: <?php echo $cttrv->getNgayRao(); ?> <br />
                            Thông Tin Chi Tiết:</br><?php echo $cttrv->getNoiDung(); ?> 
                        </div>
                        <div class="hinhanh_tinrao"> Hình Ảnh Sản Phẩm: </br>
                        <?php $chuoi = explode(" ",$cttrv->getHinhAnh());if($chuoi!=NULL) for($i=0;$i<sizeof($chuoi);$i++)
						{?>
                             <img class="image_ctraotin" src="<?php echo $chuoi[$i];?>" /></br>
                             
                             
                        <?php }?>
                                
                        </div>
                        <br /> <br /> <br /> <br />
                        <div class="binhluan_tinrao">
                        	<form method="post" action="chitiettinraovat.php?idMatrv=<?php echo $idMaTrv;?>" id= "vietbinhluan" class="vietbinhluan">
                            <div class="viet_binhluan">                            
                            	
                                	<textarea placeholder="Viết Bình Luận." class="text_binhluan" title="Viết bình luận"  name="text_binhluan" id="text_binhluan"></textarea>
                                                             
                             </div>
                             <div>
                              		<div class="bt_submitbl">
                                	 <input value="Bình luận" type="submit" class="sb_binhluan" name ="ok" id="sb_binhluan"> 
                                    </div>
                                 	<div class="hienthi_ten">
                                    	Bạn Đăng Với Tên Là: <?php echo $ttnguoidungdn->getTenHienThi();?>  <br />                                        
                                    </div>
                                    
                             </div>
                            </form>   
                             <?php 
							  $thoigian = date('Y-m-d H:i:s');
							 	
								$text="Viết bình luận";
									
								if(isset($_POST["ok"]))
								{
									if(isset($_POST["text_binhluan"])==NULL||$_POST["text_binhluan"]==$text)
									{
										?>
										<script>
											alert("bạn chưa nhập nội dung ");
										</script>
										<?php
									}
									else
									{
										 	
											 $text = $_POST["text_binhluan"];
											 $bl = new BinhLuan("",$idMaND, $idMaTrv, $thoigian, $text);
											 $binhluanBUS->insert($bl);?>
											 <script>
												alert("cám ơn bạn đã bình luận ");								  						 
											</script>
											 
											 
								<?php }}?>
                             
                             
                             
                             <br /> <br />
                             <div>
                                 <div class="tennguoi_binhluan"><?php if($binhluan!=NULL){ foreach($binhluan as $objbinhluan){?>
                                    <div class="tin_binhluan"><font color="#0000FF">                                	 
                                        
                                            <?php 										 
                                            $ttnguoidungbl= $ttnguoidungBUS->getThongTinNguoiDungByMaND($objbinhluan->getMaND());
                                            echo $ttnguoidungbl->getTenHienThi();?>: <br />
                                            Vào lúc: <?php echo $objbinhluan->getThoiGian() ?><br /></font>
                                            <div class="ctbinhluan"><font color="#000000">
                                                <?php echo $objbinhluan->getNoiDung(); ?></font>
                                            </div>
                                           
                                    </div>
                                    <?php } }?>
                                 </div>
                                <div>
                                		 <?php for($i=1;$i<=$sotrang;$i++)
                                                    {	?>											 
                                                                                                         
                                                          <a href="chitiettinraovat.php?idMatrv=<?php echo $idMaTrv;?>&&p=<?php echo $i;?>"><?php echo $i;?></a>  
                                                           <?php }?>
                                                           
                                                      
                                                 
                                                <div class="">  <a href="chitetraovat.php?idMaTrv=<?php echo $idMaTrv;?> &&p=<?php echo $sotrang;?>"    >Trang cuối</a>
                                </div>
                                  
                                
                            </div>
                        </div>
                    </div>
          	   
            	 <!-- InstanceEndEditable -->
            	 </div>
             <!--right content-->
 	       <div class="right_content">               
                
</div>
            
        </div>
        <!--Content end-->
        <div class="clr"></div><!--*xóa đi phần float left, float right*/--> 
        <!--footer-->
        <div class="footer">
<?php include("footer/footer.php") ?>
        </div>
        
    </div>
    
</body>
<!-- InstanceEnd --></html>
